#include <stdio.h>
#define N 50


int StrIndex(char *T,char *P) {
	int i=0,j=0,t=0,p=0,start=0;
	while(T[t]!='\0') t++;
	while(P[p]!='\0') p++;
	if(t == 0) return 0;
	while(i < t && j < p) {
		if(T[i] == P[j]) {
			i++;j++;
		} else {
			start++;
			i = start;
			j = 0;
		}
	}
	if (j>=p) return(start);
	else return -1;
}


char* StrRelace(char T[],char P[],char S[],char *str) {
	int i,j,k=0,t=0,p=0,s=0,pos = StrIndex(T,P);
	printf("%d",pos);
	while(T[t]!='\0') t++;
	while(P[p]!='\0') p++;
	while(S[s]!='\0') s++;
	if(t==0) return NULL;
	for(i=0;i<pos;i++)
		str[i] = T[i];
	j = i;
	while(i<i+s) {
		str[i+1] = S[k];
		i++;k++;	
	}
	while(i<t-p+s)
		str[i++] = T[j++];
	return str;

} 

int main() {
	char T[N] = "abcdadbcd";
	char P[N]= "bcd";
	char S[N] = "aceb";
	char str[N] = "";
	puts(StrRelace(T,P,S,str));
	return 0;
}
